// sgu441
// 题意：
// 有n(<=10^9)张不同照片，有k(<=min(n, 10))个认为相同的朋友，
// 现在要将这些照片分给这k个朋友，每个人至少一张，问方案数。
//
// 题解：
// f[n][k]=f[n-1][k]*k+f[n-1][k-1]
// 然后矩阵快速幂。
//
// ml:run = $bin < input
// ml:opt = 0
// ml:ccf += -g
#include <iostream>
#include <vector>

long long constexpr mod = 2007;

struct matrix
{
	using value_type = long long;
	using row_type = std::vector<value_type>;

	matrix(int ro, int co)
	{
		mat.resize(ro);
		for (auto & i : mat) i.resize(co);
	}

	matrix(int n) : matrix(n, n)
	{
		for (int i = 0; i < n; i++) mat[i][i] = 1;
	}

	matrix() = default;

	int row() const { return mat.size(); }
	int col() const { return mat[0].size(); }

	row_type       & operator[](int x)       { return mat[x]; }
	row_type const & operator[](int x) const { return mat[x]; }

	private:
	std::vector<row_type> mat;
};

matrix operator*(matrix const & a, matrix const & b)
{
	int n = a.row(), m = b.col(), t = a.col();
	matrix r(n, m);
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			for (int k = 0; k < t; k++)
				r[i][j] = (r[i][j] + (a[i][k] * b[k][j]) % mod) % mod;
	return r;
}

matrix quick_pow(matrix const & a, long long b)
{
	if (!b) return matrix(a.row());

	matrix ret = quick_pow(a, b / 2);
	ret = ret * ret;
	if (b & 1) ret = ret * a;
	return ret;
}


int n, k;

int main()
{
    std::ios_base::sync_with_stdio(false);
    std::cin >> n >> k;
    matrix a(11, 11);
    a[1][1] = 1;
    for (int i = 2; i <= 10; i++) {
        a[i][i - 1] = 1;
        a[i][i] = i;
    }
    matrix init(11, 1);
    init[1][0] = 1;
    for (int i = 2; i <= 10; i++) init[i][0] = 0;
    a = quick_pow(a, n - 1);
    init = a * init;
    std::cout << init[k][0] << "\n";
}

